package com.kongwg.java;

/**
 *
 * 创建三个窗口同时卖100张票，使用Thread接口方式
 * @author kongwg
 * @create 2020-12-04 18:07
 */
class Windows1 implements Runnable{
    private int ticket = 100;
    @Override
    public void run() {
        while (true){
            if (ticket > 0){
                System.out.println(Thread.currentThread().getName() + "窗口卖出的票号为" + ticket);
                ticket--;
            }else {
                break;
            }
        }
    }
}
public class WindowsTest1 {
    public static void main(String[] args) {
        Windows1 w1 = new Windows1();

        Thread t1 = new Thread(w1);
        t1.setName("窗口1：");
        t1.start();
        Thread t2 = new Thread(w1);
        t2.setName("窗口2：");
        t2.start();
        Thread t3 = new Thread(w1);
        t3.setName("窗口3：");
        t3.start();
    }
}
